function to reuse the code